#include "mainwindow.h"
#include <QApplication>
#include <QWindowsStyle>
#include "myhelper.h"

#include    <QtCore/QCoreApplication>
#include    <QDebug>
#include    <QtNetwork/QUdpSocket>
#include    <QHostAddress>
#include    <QDateTime>
#include    <iostream>

#include    "keyboard.h"

 QUdpSocket *udpSocket;

#define _TIME_ qPrintable(QDateTime::currentDateTime().toString("hh:mm:ss"))

static void networkLog(QtMsgType type, const char* msg)
{
    QString qstrTest;
    switch (type)
    {
            case QtDebugMsg:
                    qstrTest = QString("%1: %2").arg(_TIME_ , msg);
                    break;
            case QtWarningMsg:
                    qstrTest = QString("%1: %2").arg(_TIME_ , msg);
                    break;
            case QtCriticalMsg:
                    qstrTest = QString("%1: %2").arg(_TIME_ , msg);
                    break;
            case QtFatalMsg:
                    qstrTest = QString("%1: %2").arg(_TIME_ , msg);
                    exit(0);
    }

    QHostAddress hostaddr;
    hostaddr.setAddress( "192.168.1.223" );
    udpSocket->writeDatagram( qstrTest.toAscii(), hostaddr, 12345 );
}

int main(int argc, char *argv[])
{
    QApplication::addLibraryPath("sqldrivers");

    QApplication a(argc, argv);

    udpSocket = new QUdpSocket();

    //qInstallMsgHandler(networkLog);

    myHelper::SetUTF8Code();
    myHelper::SetStyle("outdoor");//黑色风格
//    myHelper::SetStyle("blue");//蓝色风格
//    myHelper::SetStyle("gray");//灰色风格
//    myHelper::SetStyle("navy");//天蓝色风格
//    myHelper::SetChinese();

    CKeyBoard *pInputContext = new CKeyBoard();
    a.setInputContext(pInputContext);

    MainWindow w;
  //  frmMain w;
    a.setStyle(new QWindowsStyle);
    w.show();

    return a.exec();

    udpSocket->close();
}
